"""
while循环
累加
"""

a = 0
while a < 10:
    print(a)
    a += 1

# 累加
a = 0
sumA = 0
while a < 101:
    sumA += a
    a += 1
print(sumA)

# 偶数累加
a = 0
sumA = 0
while a < 101:
    sumA += a
    a += 2
print(sumA)

# 奇数累加
a = 1
sumA = 0
while a < 101:
    sumA += a
    a += 2
print(sumA)

"""
break和continue
"""
i = 1
while i <= 5:
    if i == 4:
        print("吃饱了")
        break
    print(f"吃了第{i}个苹果")
    i += 1

i = 1
while i <= 5:
    if i == 3:
        print("有虫子")
        i += 1
        continue
    print(f"吃了第{i}个苹果")
    i += 1

"""
while循环嵌套
"""
j = 0
while j < 3:
    i = 0
    while i < 3:
        print(f"内层循环{i}")
        i += 1
    j += 1
    print(f"第{j}次循环结束")

"""
九九乘法表
"""
i = 1
while i <= 9:
    j = 1
    while j <= i:
        print(f"{i}*{j}={i * j}", end=" ")
        j += 1
    print()
    i += 1

"""
for循环
break
continue
"""
str1 = "ANSWER"
for i in str1:
    print(i)

for i in str1:
    if i == "S":
        print("不输出S")
        break
    print(i)

for i in str1:
    if i == "S":
        print("不输出S")
        continue
    print(i)

"""
while...else
break
continue
"""
i = 1
while i <= 5:
    print(f"循环第{i}次")
    i += 1
else:
    print("循环结束")

i = 1
while i <= 5:
    if i == 3:
        print(f"循环第{i}次")
        break
    i += 1
else:
    print("循环结束")

i = 1
while i <= 5:
    if i == 3:
        print(f"循环第{i}次")
        i += 1
        continue
    i += 1
else:
    print("循环结束")


"""
for...else
break
continue
"""
str1 = "ANSWER"
for i in str1:
    print(i)
else:
    print("执行结束")
# break
for i in str1:
    if i == "S":
        print("遇到e不打印")
        break
    print(i)
else:
    print("执行结束")
# continue
for i in str1:
    if i == "S":
        print("遇到e不打印")
        continue
    print(i)
else:
    print("执行结束")
